#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 100, INF = 0x3f3f3f3f;

int n;
int a[N], b[N];

void solve()
{
    cin >> n;
    vector<pair<int, int>> ans;
    for (int i = 1;i <= n;i++) cin >> a[i];
    for (int i = 1;i <= n;i++) cin >> b[i];
    for (int i = 1;i < n;i++) {
        for (int j = 1;j <= n - i;j++)
            if (a[j] > a[j + 1]) {
                swap(a[j], a[j + 1]);
                ans.push_back({ 1,j });
            }
    }
    for (int i = 1;i < n;i++) {
        for (int j = 1;j <= n - i;j++)
            if (b[j] > b[j + 1]) {
                swap(b[j], b[j + 1]);
                ans.push_back({ 2,j });
            }
    }

    for (int i = 1;i <= n;i++)
        if (a[i] > b[i]) {
            swap(a[i], b[i]);
            ans.push_back({ 3,i });
        }
    cout << ans.size() << "\n";
    for (auto it : ans) cout << it.first << " " << it.second << "\n";
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    cin >> T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}